//api地址
const baseurl = 'https://book.kakuya.club/'
function https(options){
        return new Promise((resolve,reject)=>{
            let requestJson = {
                url:baseurl+options.url,
                method:options.method || 'GET',
                timeout:30000,
				data:options.data || {},
				dataType:options.dataType || 'json'
            }
            uni.request({
            	url: requestJson.url,
            	data: requestJson.data,
				header:requestJson.header,
				sslVerify:false
            }).then(res => {
				if(res[1]){
					const requestData = res[1]
					if(requestData.statusCode===500){
						resolve([])
					}else{
						resolve(requestData.data)
					}
				}
            }).catch(err => {
            	uni.showModal({
            		content: err.errMsg,
            		showCancel: false
            	});
				reject(err)
            });
        });
    }
	
https.install = function(Vue) {
	Object.defineProperty(Vue.prototype, '$https', {
		get: function() {
			return https
		}
	})
}
	
export default https